package cn.hs.controller;

import cn.hs.entity.Course;
import cn.hs.pojo.CourseSelect;
import cn.hs.service.CourseService;
import cn.hs.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName CourseController
 * @Description TODO course的控制层
 * @Author yun
 * @Date 2024年10月23日 9:56
 * @Version 1.0
 */
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    @Qualifier("courseServiceImpl")
    private CourseService service;

    @GetMapping("/list")
    public Result selectAll(CourseSelect course){
        return service.selectAll(course);
    }
    @GetMapping("/idAnName")
    public Result selectByIdAnName(CourseSelect course){
        return service.selectAllIdAnName(course);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Course course){
        return service.add(course);
    }

    @PostMapping("/update")
    public Result update(@RequestBody Course course){
        return service.update(course);
    }

    @PostMapping("/delete")
    public Result delete(Integer id){
        return service.delete(id);
    }

   @GetMapping("/selectByTeacherIdCourses")
    public Result selectByTeacherIdCourses(Integer teacherId, @RequestParam(defaultValue = "1") int pageNum,@RequestParam(defaultValue = "5") int pageSize){
       PageInfo pageInfo = service.selectByTeacherIdCourses(teacherId, pageNum, pageSize);
       if (pageInfo.getList().size()>0){
           return Result.success(pageInfo);
       }else {
           return Result.error();
       }


   }

}
